Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

223
Visualizações
Difference between import a module with and without ".js" in es6 module

I'm recently learning chrome extension development, and find out that: When I use

import { foo } from "./index"

in background.js, I will get an error: An unknown error occurred when fetching the script., while using

import { foo } from "./index.js"

Everything just works properly. Could someone please tell me the difference between these two ways?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

ES6 needs you to reference a file for it to fetch.

Extension-less or a directory to use index from are supported by external loaders such as webpack, with correct configurations.

With these, if you import without extension, it will look for an index.js inside your import path as if it were a folder.

Or If you have a folder foo, and inside it a file index.js, you can import ./foo without the extension and it will import the index file.

Directly in ES6 as far as I'm aware (e.g. for Chrome browser direct interpretation without some loader), I believe a full file path is necessary for local imports, so you should include the .js extension when you want to import a specific file.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda